const { resolve } = require('path');
const webpack = require('webpack');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const AssetsPlugin = require('assets-webpack-plugin');
let config = {
    entry: {
        index: [
            'react-hot-loader/patch',
            'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
            './app/index.js',
        ],
        vendor: [
            'react',
            'react-dom',
            'redux',
            'react-redux',
        ],
    },
    output: {
        path: resolve(__dirname, 'dist/web'),
        filename: '[name].[hash].js',
        publicPath: '/',
    },
    resolve: {
        extensions: ['.jsx', '.js', '.scss', '.json'],
    },
    devtool: '#source-map',
    module: {
        rules: [
            {
                test: /(\.jsx)|(\.js)$/,
                use: [
                    'babel-loader', 'eslint-loader',
                ],
                exclude: /node_modules/,
            },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [{
                        loader: 'css-loader',
                    }, {
                        loader: 'postcss-loader',
                    }],
                }),
            },
            {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [{
                        loader: 'css-loader',
                    }, {
                        loader: 'sass-loader',
                    }, {
                        loader: 'postcss-loader',
                    }],
                }),
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                },
            },
        ],
    },

    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
        }),
        new AssetsPlugin({
            filename: './server/public/manifest.json',
        }),
        new webpack.HotModuleReplacementPlugin(),
        new ExtractTextPlugin('[name].[hash].css'),
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor', 'manifest'],
            filename: '[name].[hash:8].js',
        }),
        new webpack.NamedModulesPlugin(),
        new ProgressBarPlugin({ summary: false }),
    ],
};
module.exports = config;
